/******************************************************************************
GameGuts.cpp

  -Implements the GameGuts class, which is the base for concrete
   game logic implemented in this server module.
******************************************************************************/
#include <windows.h>

#include "kenoproto.h"
#include "GameGuts.h"
#include "GameConnection.h"
#include "SubGameData.h"
#include "KenoGuts.h"
#include "BonusBingoGuts.h"

/******************************************************************************
Construction / Destruction
******************************************************************************/

GameGuts::GameGuts(GameConnection* connection)
{
    m_connection = connection;
    m_compFactor = 0;
	m_subGame = NULL;
    memset(m_anDenomValues, 0, sizeof(m_anDenomValues));

#ifdef FORCED_KENO
	m_forcedResults = 0;
#endif
}

GameGuts::~GameGuts()
{
    delete m_subGame;

#ifdef FORCED_KENO
	if (m_forcedResults)
	{
		delete m_forcedResults;
		m_forcedResults = 0;
	}
#endif
}

/******************************************************************************
Member Methods
******************************************************************************/

void GameGuts::setCompFactor(int32 compFactor)
{
    m_compFactor = compFactor;
}

int32 GameGuts::getCompFactor() const
{
	if ( m_connection->getInfo()->forMoney )
		return m_compFactor;
	else
		return 0;
}

bool8 GameGuts::allowsMultipliers() const
{
    return false;
}

bool8 GameGuts::hasSubGame() const
{
    return false;
}

void GameGuts::processMultiplierResponse(uint8* msgbuf, int32 nMsgLen)
{
    //Default implementation does not do multipliers
    //So, we should never get here.
    //If you override allowsMultipliers to return true,
    //you need to handle the multiplier reponse, too.
    ASSERT( allowsMultipliers() );
}

bool8 GameGuts::getSavedGame() 
{
    //Default is to never have saved game state.
    return false;
}

void GameGuts::processSubGameMessage()
{
	//Default implementation does not have a subgame
	ASSERT( hasSubGame()  );
}

void GameGuts::allocateSubGameData()
{
    pInfo info = m_connection->getInfo();

    m_subGame = new SubGame(getMachineID(), info->pid,
                            0, info->forMoney);
}
/*******************************************************************************
Message Helpers
******************************************************************************/
void
GameGuts::answer(uint8 answer)
{
    startResponse();
    addToResponse( answer );
    endResponse();
}

void
GameGuts::addToResponse(uint8 add_byte)
{
    m_connection->msgAdd( add_byte );
}

void
GameGuts::addToResponse(int8 add_sbyte)
{
    m_connection->msgAdd( add_sbyte );
}

void
GameGuts::addToResponse(int32 add_int)
{
    m_connection->msgAdd( add_int );
}

void
GameGuts::startResponse()
{
    m_connection->msgStart();
}

void
GameGuts::endResponse()
{
    m_connection->msgEnd();
}

/******************************************************************************
Static Methods
******************************************************************************/
GameGuts* 
GameGuts::CreateGuts(uint8 machid, GameConnection* connection)
{
    GameGuts* guts = NULL;

    switch ( machid )
    {
    case KENO_MACH_ID:
        //Create a Keno gut        
        return new KenoGuts(connection);
        break;
    case BONUS_BINGO_MACH_ID:
        //Create a Bonus Bingo gut
        return new BonusBingoGuts(connection);
        break;
    default:
        //Bad news
        ASSERT( !"Couldn't create a valid GameGuts instance." );
    }
    return guts;
}

#ifdef FORCED_KENO
void GameGuts::loadForcedResults()
{
	// CSN-12127 - To be implemented in derived class
}
#endif
